package com.fds.netty;

import com.fds.netty.config.MyServerConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.env.Environment;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.net.InetSocketAddress;

@SpringBootApplication
@ComponentScan
@EnableSwagger2
@Slf4j
public class Application implements CommandLineRunner {

    @Autowired
    private MyServerConfig myServerConfig;

    public static void main(String[] args) {
        ConfigurableApplicationContext application = SpringApplication.run(Application.class, args);
        Environment env = application.getEnvironment();
        String port = env.getProperty("server.port");
        String path = env.getProperty("server.servlet.context-path");
        log.info("\n----------------------------------------------------------\n\t"
                + "Application swagger URL:\n\t" + "Local: \t\thttp://localhost:" + port + path + "index"
                + "\n\t" + "----------------------------------------------------------");
    }

    @Override
    public void run(String... args) throws Exception {
        myServerConfig.start(new InetSocketAddress("127.0.0.1", 9999));
    }
}
